package be.vdab.gwt.cultuurhuis.client.managers;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.HistoryListener;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;


/**
 * 
 * @author stijn
 *
 * Documentation: http://code.google.com/intl/nl-NL/webtoolkit/doc/latest/DevGuideCodingBasicsHistory.html
 */
public class HistoryManager {
	
	private ApplicationManager appManager;
	
	public HistoryManager(ApplicationManager appManager) {		
		this.appManager = appManager;
		init();
	}
	
	protected void init(){
		final HistoryManager me = this;	
		
		History.addValueChangeHandler(new ValueChangeHandler<String>() {			
			@Override
			public void onValueChange(ValueChangeEvent<String> event) {
				me.procesHistoryValueChange(event);
			}							
		});				
	}
	
	public void procesHistoryValueChange(ValueChangeEvent<String> event) {
		String[] tokens = event.getValue().split("/");
		String firstLevel = tokens[0];
		if(firstLevel.toLowerCase()=="voorstelling"){
			appManager.showVoorstelling(tokens[1]);
		}				
	}
	

	public void newItem(String historyToken){
		History.newItem(historyToken);
	}
}
